package com.project.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.project.bean.OrderPInfoBean;
import com.project.bean.PurchaseOrderBean;
import com.project.mapper.IOderPInfoMapper;
import com.project.mapper.IPurchaseOrderMapper;
import com.project.service.IPurchaseOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;

/**
 * 采购订单实现类
 */

@Service
@Transactional
public class PurchaseOrderServiceImpl implements IPurchaseOrderService {
    @Autowired
    private IPurchaseOrderMapper purchaseOrderMapper;
    @Autowired
    private IOderPInfoMapper oderPInfoMapper;
    @Override
    public IPage<PurchaseOrderBean> cutByItem(Integer pageNO, String provider, LocalDate startDate, LocalDate endDate) {
        QueryWrapper<PurchaseOrderBean> qw=new QueryWrapper<>();
        if (provider !=null && provider.length() !=0){
            qw.like("p_supplier",provider);
        }
        if (startDate !=null){
            qw.ge("p_poDate",startDate);
        }
        if (endDate !=null){
            qw.le("p_poDate",endDate);
        }
        return purchaseOrderMapper.selectPage(new Page<>(pageNO,3),qw);
    }

    @Override
    public PurchaseOrderBean findOrderById(Integer purchaseOrderId) {
        PurchaseOrderBean purchaseOrderObj=purchaseOrderMapper.selectById(purchaseOrderId);
        purchaseOrderObj.setOrderPInfoList(oderPInfoMapper.findByorderId(purchaseOrderId));
        return purchaseOrderObj;
    }
}
